﻿@using System.Web.Services.Description
@using Microsoft.Web.Mvc
@using MvcContrib.UI.Grid
@using ENail.Portal.Web.Controllers
@using Telerik.Web.Mvc
@using Enail.UI
@using ENail.Portal.Web.Models

@model ENail.Portal.Web.Models.EntryViewModel

@{
    ViewBag.Title = "Entry";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<script type="text/javascript" src="../../Scripts/jquery-1.6.4.js"></script>
<script type="text/javascript" src="../../Scripts/jquery.autocomplete.js"></script>

<script language="javascript">
//    var options, a;
//    jQuery(function () {
//        options = { serviceUrl: '/Entry/GetCustomers' };
//        a = $('#Customer_FirstName').autocomplete(options);
    //    });
    function goTo(id) {
        var url = '/entry/index/';
        if (id != -1)
            url = '/entry/index/'+id;
        location.href = url;
    }
    //delete assignment
    function delAssignment(rid, aid) {
        if (confirm('Are you sure to delete this assignment?')) {
            var url = '/entry/delassignment/' + rid + '/' + aid;
            location.href = url;
        }
    }

    function getElement(id) {
        return document.getElementById(id);
    }
    function onLoad() {
        //split birthday column to fill in 2 month,day columns
        var birthDay = getElement('Customer_Birthday').value;
        if(birthDay.length>0)
        {
            var array = birthDay.split('/');
            if(array.length=2) {
                getElement("Birthday_Month").value = array[0];
                getElement("Birthday_Day").value = array[1];
                
            }
        }
    }
    window.onload = function () {
        onLoad();
    };
    function mySubmit() {
        var birthDayMonth = getElement("Birthday_Month").value;
        var birthDayDay = getElement("Birthday_Day").value;
        if (birthDayMonth != '' && birthDayDay != '') 
        {
            getElement('Customer_Birthday').value = birthDayMonth + '/' + birthDayDay;
        }
        else {
            getElement('Customer_Birthday').value = "";
        }
        document.forms(0).submit();
    }
</script>

<div id="container_home_main" >
<div style="background-color:#edd2ca;width:645px;height:15px;text-align:center;padding:5px"> <font style="color:#5b362c;font-weight:bold">@ViewBag.Title</font> </div>
<div id="container_content">

@using (Html.BeginForm<EntryController>(x => x.Save(null), FormMethod.Post, new { @id = "form1", @onSubmit = "alert('submit')" }))
{
    @Html.HiddenFor(x => x.RegistrationId)
@*    <table>
        <tr>
            <td>@Html.SubmitButton("Done")</td>
        </tr>
    </table>
*@
    @Html.ValidationSummary()
    <div id="customer">
        <table>
            <tr>
                <td>
                    @*                    @Html.DropDownListFor(x => x.RegistrationId,
                            new SelectList(Model.Registrations.List,
                                           "Id",
                                           "CustomerName"),
                            "-Select Registration-")
*@                

                </td>
            </tr>
            <tr valign="top">
                <td>
                    <table cellspacing="3">
                        @Html.HiddenFor(x => x.Customer.Id)
                        <tr>
                            <td>
                                <h3>Customer:</h3>
                            </td>
                            <td >
                                <select id="cmbRegistrations" name="registrations" onchange=" goTo(this.value);">
                                    <option value="-1">-- New registration--</option>
                                    @foreach (var ele in Model.Registrations.List)
                                    {
                                        <option @(ele.Id == Model.RegistrationId ? "selected" : " ") value="@ele.Id">@ele.CustomerName</option>
                                    }
                                </select>
                            </td>
                            <td></td><td></td>
                        </tr>
                        @*                        <tr>
                            <td>Customer Id:</td>
                            <td>@(Model.Customer.Id == 0 ? "-New-" : Model.Customer.Id.ToString())</td> 
                        </tr>
*@                        <tr>
                              <td>First Name:</td>
                              <td>@Html.TextBoxFor(x => x.Customer.FirstName, new Dictionary<string, object> {{"maxlength", "50"},{"size","20"}})</td>
                              <td>Phone:</td>
                              <td>@Html.TextBoxFor(x => x.Customer.Phone, new Dictionary<string, object> { { "maxlength", "20" },{"size","20"} })</td>
                        </tr>
                        <tr>
                            <td>Last Name:</td>
                            <td>@Html.TextBoxFor(x => x.Customer.LastName, new Dictionary<string, object> { { "maxlength", "50" }, { "size", "20" } })</td>
                            <td>Email:</td>
                            <td>@Html.TextBoxFor(x => x.Customer.Email, new Dictionary<string, object> {{"maxlength", "50"},{"size","20"}})</td>

                        </tr>
@*                        <tr>
                            <td>Title:</td>
                            <td>@Html.TextBoxFor(x => x.Customer.Title, new { maxlength = 3, size = 3 })</td>
                        </tr> *@
                        <tr>
                            <td>BirthDay:</td>
                            <td>@Html.HiddenFor(x => x.Customer.BirthDay)
                                <select name="Birthday_Month">
                                    <option value=""></option>
                                    <option value="01">01</option>
                                    <option value="02">02</option>
                                    <option value="03">03</option>
                                    <option value="04">04</option>
                                    <option value="05">05</option>
                                    <option value="06">06</option>
                                    <option value="07">07</option>
                                    <option value="08">08</option>
                                    <option value="09">09</option>
                                    <option value="10">10</option>
                                    <option value="11">11</option>
                                    <option value="12">12</option>
                                </select>
                                /
                                <select name="Birthday_Day">
                                    <option value=""></option>
                                    <option value="01">01</option>
                                    <option value="02">02</option>
                                    <option value="03">03</option>
                                    <option value="04">04</option>
                                    <option value="05">05</option>
                                    <option value="06">06</option>
                                    <option value="07">07</option>
                                    <option value="08">08</option>
                                    <option value="09">09</option>
                                    <option value="10">10</option>
                                    <option value="11">11</option>
                                    <option value="12">12</option>
                                    <option value="13">13</option>
                                    <option value="14">14</option>
                                    <option value="15">15</option>
                                    <option value="16">16</option>
                                    <option value="17">17</option>
                                    <option value="18">18</option>
                                    <option value="19">19</option>
                                    <option value="20">20</option>
                                    <option value="21">21</option>
                                    <option value="22">22</option>
                                    <option value="23">23</option>
                                    <option value="24">24</option>
                                    <option value="25">25</option>
                                    <option value="26">26</option>
                                    <option value="27">27</option>
                                    <option value="28">28</option>
                                    <option value="29">29</option>
                                    <option value="30">30</option>
                                    <option value="31">31</option>
                                </select>

                            </td>
                        </tr>
@*                        <tr>
                            <td>Address:</td>
                            <td>@Html.TextBoxFor(x => x.Customer.Address)</td>
                        </tr>
*@                    </table>
                </td>
                <td>
                    <table>
                        
                        @*                        <tr>
                            <td>City:</td>
                            <td>@Html.TextBoxFor(x => x.Customer.City)</td> 
                        </tr>
                        <tr>
                            <td>State:</td>
                            <td>@Html.TextBoxFor(x => x.Customer.State)</td>
                        </tr>   
                        <tr>
                            <td>Zip:</td>
                            <td>@Html.TextBoxFor(x => x.Customer.Zip)</td>
                        </tr> 
                        <tr>
                            <td>Country:</td>
                            <td>@Html.TextBoxFor(x => x.Customer.Country)</td>
                        </tr>
*@
                    @*                        <tr>
                            <td>Mobile:</td>
                            <td>@Html.TextBoxFor(x => x.Customer.Mobile)</td>
                        </tr>   
                        *@
                    </table>
                </td>
            </tr>
        </table>
        
    </div>
    <hr />
    <h3>Assignment:</h3>
    <div id="assignment">
        <table cellspacing="5">
        <tr>
            <td>Employee:</td>
            <td>@Html.DropDownListFor(x => x.Assignment.EmployeeId,
                             new SelectList(Model.Assignment.Employees,
                                                    "Id",
                                                    "EmployeeName"),
                                    "-Select Employee-")
            </td>
            <td>Nail Service:</td>
            <td>@Html.DropDownListFor(x => x.Assignment.NailServiceId,
                             new SelectList(Model.Assignment.NailServices,
                                                    "Id",
                                                    "ServiceName"),
                                    "-Select Service-")
            </td>
            <td><input type="button" value="Save" onclick="mySubmit()"/></td>
        </tr>
        </table>
        <table>
            <tr>
                <td>
                    @Html.Grid(Model.Assignment.Assignments).Columns(column =>
                                                           {
                                                               
                                                               column.For(x => x.EmployeeName)
                                                                   .Named("Employee").Header("Employee")
                                                                   .Attributes(width => "150px");
                                                               column.For(x => x.ServiceName)
                                                                   .Named("Service")
                                                                   .Attributes(width => "400px");
                                                               //column.For(x => Html.ActionLink("Delete", "Index", new { id = x.Id })).Named("Delete");
                                                               //column.For(x => x.Id>0 ? "<button onclick='delAssignment(" + Model.RegistrationId + "," + x.Id + ")'>delete</button>" : "").Named("Delete").Header(x => "<img width=15px src=" + @Url.Content("~/Content/images/del.jpg") + " />" ).Encode(false);
                                                               column.For(x => (x.Id > 0 ) ? "<button onclick='delAssignment(" + Model.RegistrationId + "," + x.Id + ")'>delete</button>" : "").Named(" ").Encode(false);
                                                           }
           ).Attributes(@class => "grid"
           ).HeaderRowAttributes(new Dictionary<string, object> { { "class", "gridheaderrow" } }
           //).RowAttributes(row => new Dictionary<string, object> { { "onclick", "document.location='" + Url.Action("Update", new { Id = row.Item.Id }) + "'" } }
).RenderUsing(new AlwaysRenderHeaderRenderer<AssignmentItemViewModel>())
                    
                </td>
            </tr>
        </table>
    </div>
}
        </div>
	      </div>
          <div id="container_home_right">@{
            Html.RenderAction("InitializeTask");   
        }
</div>

